<?php

/**
 * This is the model class for table "tbl_payment".
 *
 * The followings are the available columns in table 'tbl_payment':
 * @property string $id
 * @property string $transection_id
 * @property string $user_pay
 * @property string $pay_at
 * @property string $order_id
 * @property string $form_id
 * @property double $amount
 * @property string $sender_name
 * @property string $detail
 * @property integer $type
 */
class Payment extends CActiveRecord
{
    const ONLINE = 0;
    const CHUYEN_KHOAN = 1;

    /**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_payment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('form_id', 'required'),
			array('type', 'numerical', 'integerOnly'=>true),
			array('amount', 'numerical'),
			array('transection_id, order_id', 'length', 'max'=>50),
			array('user_pay, form_id', 'length', 'max'=>20),
			array('sender_name', 'length', 'max'=>150),
			array('pay_at, detail', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, transection_id, user_pay, pay_at, order_id, form_id, amount, sender_name, detail, type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'transection_id' => 'Transection',
			'user_pay' => 'User Pay',
			'pay_at' => 'Pay At',
			'order_id' => 'Order',
			'form_id' => 'Form',
			'amount' => 'Amount',
			'sender_name' => 'Sender Name',
			'detail' => 'Detail',
			'type' => 'Type',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('transection_id',$this->transection_id,true);
		$criteria->compare('user_pay',$this->user_pay,true);
		$criteria->compare('pay_at',$this->pay_at,true);
		$criteria->compare('order_id',$this->order_id,true);
		$criteria->compare('form_id',$this->form_id,true);
		$criteria->compare('amount',$this->amount);
		$criteria->compare('sender_name',$this->sender_name,true);
		$criteria->compare('detail',$this->detail,true);
		$criteria->compare('type',$this->type);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Payment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
